import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
/**
 * 
 */

/**
 * @author joseph
 *
 */
public class downloadImage {
	public static void main( String[] argv ) throws Exception
	  {
		String line = null;
		String problem = "";
		String strval="name=\"leaf\"";
		String problem1="";
		int count=0;
		
	    URL url = new URL( "http://www.indiaglitz.com/channels/tamil/gallery/Actress/4680.html" );
		InputStream stream = url.openStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
				
		while((line=reader.readLine())!=null){
			if(line.contains(strval)){
				problem = line.substring(line.indexOf("http:"),line.indexOf(".jpg")+4 );
				if (!problem1.equals(problem)){
					System.out.println(problem+"\n");
		        	String str1=problem.substring(problem.lastIndexOf("/")+1);
		        	System.out.println (str1);
		        	 URL url1 = new URL(problem);
		        	 InputStream in = new BufferedInputStream(url1.openStream());
		        	 ByteArrayOutputStream out = new ByteArrayOutputStream();
		        	 byte[] buf = new byte[1024];
		        	 int n = 0;
		        	 while (-1!=(n=in.read(buf)))
		        	 {
		        	    out.write(buf, 0, n);
		        	 }
		        	 out.close();
		        	 in.close();
		        	 byte[] response = out.toByteArray();
		        	 FileOutputStream fos = new FileOutputStream("d://dimage//"+str1);
		        	    fos.write(response);
		        	    fos.close();
					count++;
						}
				problem1=problem;
		}
		}
		System.out.println("TOTAL NO OF FILES"+count);
		
	  } 
}
